<?php
/**
 * @开放类
 * 1、企业list
 * 2、注册
 * 3、忘记密码
 * 4、修改资料 
 * @作者 
 * 万全强（php）
 */
namespace app\controller;

use app\controller\HomeBase;
use think\facade\Db;
use app\libs\Predis;



class Open extends HomeBase
{
	

    public function __construct(){
               
        parent::__construct(); 
    }
    /***
     * 通过邮编返回地图json
     */
    public function GetMapJsonByCode(){
    	$code = request()->get('code','','trim');
    	$type = request()->get('type','','trim');
    	
    	
    	$key='MapJsonByCode_'.$code.'_'.$type;
    	$cache = new Predis();
    	$data=$cache->get($key);
    	if($data){
    		$result=unserialize($data);
    	}else{
    		$url="https://geo.datav.aliyun.com/areas_v2/bound/{$code}{$type}.json";
    		$result=json_decode(file_get_contents($url),true);
    		$cache->set($key,serialize($result),3600);
    	}
    	
    	return json(['status'=>1,'msg'=>'获取成功','data'=>$result]);
    }
    /**
     * 上传接口
     * @return \think\response\Json
     */
    public function UploadFife(){
    	$file = request()->file('file');
    	if(empty($file)) {
    		return json(['status'=>0,'msg'=>'请选择上传文件','data'=>[]]);
    	}
    	$filepath='file';
    	$savename = \think\facade\Filesystem::disk('public')->putFile($filepath, $file);
    	
    	if($savename){
    		$url = config('app.LocalIp').'/storage/'.$savename;
    		return json(['status'=>1,'msg'=>'上传成功','data'=>['url'=>$url]]);
    	}else{
    		// 上传失败获取错误信息
    		return json(['status'=>0,'msg'=>'上传失败','data'=>[]]);
    	}
    	
    }
    
    
    

}